import { _decorator, Component, Label, Node } from 'cc';
import { ssclass, sseffect } from '../state-signals';
import { account, userInfo } from '../store/user-info';
import { VMBase } from '../state-signals/view/VMBase';
const { ccclass, property } = _decorator;

@ccclass('MainView')
@ssclass
export class MainView extends Component {
    nameC = 'main_view';

    infoNode: Node

    disposeNode: Node

    count = 0

    state = userInfo

    onLoad() {
        this.infoNode = this.node.getChildByName('info')
        this.disposeNode = this.node.getChildByName('dispose')
        console.log('MainView onLoad ...', this.infoNode, this.node.name);
        this.effect();

        let comps = this.getComponentsInChildren(VMBase)
        console.log('comps ...', comps);
    }

    update(deltaTime: number) {
        
    }

    @sseffect
    setMoney() {
        this.node.getChildByName('money').getComponent(Label).string = `金币: ${account.coin}\n钱: ${account.money}`
    }

    @sseffect
    effect() {
        console.log('not tracker effect ...', this.nameC);
    }

    @sseffect
    setInfo() {
        let label = this.infoNode.getComponent(Label)
        label.string = `姓名: ${userInfo.name}\n年龄: ${userInfo.age}\n性别: ${userInfo.sex}`

        return () => {
            let la = this.disposeNode.getComponent(Label)
            la.string = `dispose: ${this.count++}`
        }
    }
}
